<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Code extends Model
{
    //
    public function getRand()
    {
        $data = Code::orderBy(DB::raw('RAND()'))
            ->take(1)
            ->first();
        session(["answer"=>$data["answer"]]);
        return $data["question"];
    }
    public function checkCode($answer)
    {
        if ($answer != session("answer")){

            exit(json_encode(['error'=>1,"info"=>"验证码错误"]));
        }
    }
}
